package helpers;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Locale;

public class NumberHelper {
	public static String numberFormat(long num) {
		String number = "";
		NumberFormat nf = NumberFormat.getNumberInstance(Locale.GERMAN);  
		return nf.format(num);
	}
	
	public static String numberFormat(int num) {
		String number = "";
		NumberFormat nf = NumberFormat.getNumberInstance(Locale.GERMAN);  
		return nf.format(num);
	}
	
	public static String numberFormat(double num) {
		return String.format("%10.5f", num);
	}
	
	public static String readableFileSize(long size) {
	    if(size <= 0) return "0";
	    final String[] units = new String[] { "B", "KB", "MB", "GB", "TB" };
	    int digitGroups = (int) (Math.log10(size)/Math.log10(1024));
	    return new DecimalFormat("#,##0.#").format(size/Math.pow(1024, digitGroups)) + " " + units[digitGroups];
	}
}
